//
//  CQForwardCell.swift
//  swift-weibo
//
//  Created by 陈乾 on 15/11/1.
//  Copyright © 2015年 陈乾. All rights reserved.
//

import UIKit

class CQForwardCell: CQHomeTableViewCell {

    
   override var status : CQStatus? {
        didSet{
          
        let name = status?.retweeted_status?.user?.name ?? "名字为空"
         let text = status?.retweeted_status?.text ?? "内容为空"
            forwardLable.text = "@\(name): \(text)"
        }
    }
    //1重写父类的准备UI自己 重新布局 转发微博的 文字 和图片
    
    override func prepareUI() {
        //父类的准备UI
        super.prepareUI()
        
        //添加子空间
        //将背景按钮插入到图片视图的下面
        contentView.insertSubview(dimBkgBtn, belowSubview: pictureView)
        contentView.addSubview(forwardLable)
        
        dimBkgBtn.translatesAutoresizingMaskIntoConstraints = false
//        
//        contentView.addConstraint(NSLayoutConstraint(item: dimBkgBtn, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: contentLabel, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 8))
//        
//        contentView.addConstraint(NSLayoutConstraint(item: dimBkgBtn, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: bottomView, attribute: NSLayoutAttribute.Top, multiplier: 1, constant: 0))
//        
//        contentView.addConstraint(NSLayoutConstraint(item: dimBkgBtn, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: UIScreen.screenWidth()))
//        
        
      //  添加约束
        //背景button的左上角约束
        dimBkgBtn.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: contentLabel, size: nil, offset: CGPointMake(-CQMargin, CQMargin))
        
        //背景button的右下角约束
        dimBkgBtn.ff_AlignVertical(type: ff_AlignType.TopRight, referView: bottomView, size: nil)
        
        
        //转发微博的内容label约束
        forwardLable.ff_AlignInner(type: ff_AlignType.TopLeft, referView: dimBkgBtn, size: nil, offset: CGPointMake(CQMargin, CQMargin))
        //宽度
        contentView.addConstraint(NSLayoutConstraint(item: forwardLable, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: UIScreen.screenWidth() - 16))
        
        ///视图view的约束
               let cons = pictureView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: forwardLable, size: CGSize(width: 0, height: 0), offset: CGPointMake(0, 8))
                //取出宽度约束
                 pictureConsWidth = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Width)
                //取出高度约束
                pictureConsHeight = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Height)
        
        
        
    }
    
    
    //MARK: - 懒加载
    //背景按钮
    private lazy var dimBkgBtn: UIButton = {
        
        let dimBtn = UIButton()
        dimBtn.backgroundColor = UIColor(white: 0.9, alpha: 1)

        return dimBtn
        }()
    //转发的文字内容
    private lazy var forwardLable: UILabel = {
        let label = UILabel()
        
//        label.text = "xxxxxxxxxoooooooooooxoxoxoxoxoox"
        //需要换行
        label.numberOfLines = 0
        //字体颜色
        label.textColor = UIColor.darkGrayColor()
        
        return label
        }()
    

}
